package com.amit.struts;


import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class LoginForm  extends ActionForm{
	
	private String username="amit";
	private String password;
	
	
public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
	
this.username="amityadav";

}

@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
	ActionErrors errors=new ActionErrors();
	
	if(username==null||username.length()==0)
	{
		errors.add("username", new ActionError("error.login.un"));
	}
	else if(password==null||password.length()==0)
	{
		errors.add("password", new ActionError("error.login.pw"));
	}
	else if(username.length()<4)
	{
		errors.add("username", new ActionError("error.login.un.min"));
	}
	
	else if(username.length()>8)
	{
		errors.add("username", new ActionError("error.login.un.max"));
	}
	else if(password.length()<4)
	{
		errors.add("password", new ActionError("error.login.pw.min"));
	}
	
	else if(password.length()>8)
	{
		errors.add("password", new ActionError("error.login.pw.max"));
	}
	
		
		return  errors;
	}
}
